package com.nuoniu.sibanyun.service.cm.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nuoniu.sibanyun.entity.cm.CmContractStage;
import com.nuoniu.sibanyun.mapper.cm.CmContractStageMapper;
import com.nuoniu.sibanyun.service.cm.ICmContractStageService;
import com.nuoniu.sibanyun.userThread.UserInfo;
import com.nuoniu.sibanyun.userThread.UserThreadLocal;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 合同阶段 服务实现类
 * </p>
 *
 * @author 小啊刚
 * @since 2021-10-20
 */
@Service
public class CmContractStageServiceImpl extends ServiceImpl<CmContractStageMapper, CmContractStage> implements ICmContractStageService {

    @Override
    public Page<CmContractStage> pageList(Page page, CmContractStage contractStage) {
        QueryWrapper wrapper = new QueryWrapper();
        UserInfo userInfo = UserThreadLocal.get();
        wrapper.eq("company_id", userInfo.getCompanyId());
        if(contractStage.getGroupId() != null) {
            wrapper.eq("group_id", contractStage.getGroupId());
        }else {
            wrapper.isNull("group_id");
        }

        return page(page, wrapper);
    }

    @Override
    public void saveStage(CmContractStage contractStage) {
        if(contractStage.getId() == null) {
            UserInfo userInfo = UserThreadLocal.get();
            contractStage.setCompanyId(userInfo.getCompanyId());
        }

        this.saveOrUpdate(contractStage);
    }
}
